package cz.muni.fi.pa165.sme.web.pages.sportActivityRecord;

import java.util.List;

import cz.muni.fi.pa165.sme.api.SportActivityRecordService;
import cz.muni.fi.pa165.sme.web.converters.ConvertUtils;
import cz.muni.fi.pa165.sme.web.fo.SportActivityRecordFO;
import cz.muni.fi.pa165.sme.web.pages.TemplatePage;
import cz.muni.fi.pa165.sme.web.panels.sportActivityRecord.RecordListPanel;
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.springframework.core.convert.ConversionService;
import org.springframework.security.access.prepost.PreAuthorize;

/**
 * @author jirankova
 */
@AuthorizeInstantiation(Roles.USER)
public class RecordListPage extends TemplatePage {

	@SpringBean
	private SportActivityRecordService sportActivityRecordService;

	@SpringBean(name = "conversionServiceFe")
	private ConversionService conversionService;

	public RecordListPage() {
		init(ConvertUtils.convertList(sportActivityRecordService.findAllSportActivityRecords(), conversionService, SportActivityRecordFO.class));
	}

	private void init(final List<SportActivityRecordFO> sportActivityRecordFOs) {
		add(new Label("title", new ResourceModel("title")));
		add(new RecordListPanel("recordListPanel", sportActivityRecordFOs));
	}

}
